#include "event.h"

namespace burn {

CStatus GEvent::run() {
  CGRAPH_FUNCTION_BEGIN
  CGRAPH_ASSERT_NOT_NULL(this->thread_pool_)

  // 触发一个事件，放到辅助线程中去，异步执行
  thread_pool_->commit([this] { this->trigger(this->param_); },
                       CGRAPH_EVENT_TASK_STRATEGY);
  CGRAPH_FUNCTION_END
}

CStatus GEvent::process(GEventType type) {
  CGRAPH_FUNCTION_BEGIN

  switch (type) {
  case GEventType::SYNC: // 同步触发
    this->trigger(this->param_);
    break;
  case GEventType::ASYNC: // 异步触发
    CGRAPH_ASSERT_NOT_NULL(this->thread_pool_)
    thread_pool_->commit([this] { this->trigger(this->param_); },
                         CGRAPH_EVENT_TASK_STRATEGY);
    break;
  default:
    CGRAPH_RETURN_ERROR_STATUS("unknown event type")
  }

  CGRAPH_FUNCTION_END
}

} // namespace burn